<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->

          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <!-- <a-col :md="6" :sm="24">
                <a-form-item prop="code">
                  <a-select v-model="lanCode" size="large" @change="lanCodeChange">
                    <a-select-option value="zh"> 中文 </a-select-option>
                    <a-select-option value="en"> English </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col> -->
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('setailManagement.documentNo')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('setailManagement.pleaseEnterTheDocumentNumber')"
                    v-model="queryParam.number"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('setailManagement.productInformation')" :labelCol="labelCol"
                  :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('setailManagement.pleaseEnterBarcodeNameSpecificationAndModel')"
                    v-model="queryParam.materialParam"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('setailManagement.documentDate')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker style="width: 100%" v-model="queryParam.createTimeRange" format="YYYY-MM-DD"
                    :placeholder="[$t('setailManagement.startTime'), $t('setailManagement.endTime')]" 
                    @change="onDateChange" @ok="onDateOk" />
                </a-form-item>
              </a-col>
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">{{ $t('setailManagement.query') }}</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">{{ $t('setailManagement.reset') }}</a-button>
                  <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? $t('setailManagement.putAway') : $t('setailManagement.open') }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                  </a>
                </a-col>
              </span>
              <template v-if="toggleSearchStatus">
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.membershipCardNumber')" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('setailManagement.number')" showSearch optionFilterProp="children"
                      v-model="queryParam.organId">
                      <a-select-option v-for="(item, index) in retailList" :key="index" :value="item.id">
                        {{ item.supplier }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.warehouseName')" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('setailManagement.warehouse')" showSearch optionFilterProp="children"
                      v-model="queryParam.depotId">
                      <a-select-option v-for="(depot, index) in depotList" :value="depot.id">
                        {{ depot.depotName }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.operator')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('setailManagement.operator')" showSearch optionFilterProp="children"
                      v-model="queryParam.creator">
                      <a-select-option v-for="(item, index) in userList" :key="index" :value="item.id">
                        {{ item.userName }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.settlementAccount')" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('setailManagement.account')" showSearch optionFilterProp="children"
                      v-model="queryParam.accountId">
                      <a-select-option v-for="(item, index) in accountList" :key="index" :value="item.id">
                        {{ item.name }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <!-- <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.documentStatus')" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('setailManagement.status')" v-model="queryParam.status">
                      <a-select-option value="0">{{ $t('setailManagement.notApproved') }}</a-select-option>
                      <a-select-option value="1">{{ $t('setailManagement.reviewed') }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col> -->
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.settlementStatus')" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('setailManagement.settlementStatus')" v-model="queryParam.purchaseStatus">
                      <a-select-option value="0">{{ $t('setailManagement.Unsettled') }}</a-select-option>
                      <a-select-option value="1">{{ $t('setailManagement.Settled') }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('setailManagement.notesToDocuments')" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
                    <a-input  v-model="queryParam.remark"></a-input>
                  </a-form-item>
                </a-col>
              </template>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <!-- <a-button v-if="btnEnableList.indexOf(1) > -1" @click="myHandleAdd" type="primary" icon="plus">{{
              $t('setailManagement.newlyAdded')
          }}</a-button> -->
          <ColumnsSetting @columnsChange="columnsChange" :columns="columns"></ColumnsSetting>
          <a-dropdown>
            <a-menu slot="overlay">
              <a-menu-item key="1" v-if="btnEnableList.indexOf(1) > -1" @click="batchDel"><a-icon type="delete" />{{
                  $t('setailManagement.delete')
              }}</a-menu-item>
              <!-- <a-menu-item key="2" v-if="btnEnableList.indexOf(2) > -1" @click="batchSetStatus(1)"
                ><a-icon type="check" />{{ $t('setailManagement.toExamine') }}</a-menu-item
              >
              <a-menu-item key="3" v-if="btnEnableList.indexOf(7) > -1" @click="batchSetStatus(0)"
                ><a-icon type="stop" />{{ $t('setailManagement.DeApproval') }}</a-menu-item
              > -->
            </a-menu>
            <a-button> {{ $t('setailManagement.batchOperation') }} <a-icon type="down" /> </a-button>
          </a-dropdown>
          <a-tooltip placement="left" :title="$t('setailManagement.arrears')" slot="action">
            <a-icon v-if="btnEnableList.indexOf(1) > -1" type="question-circle" style="font-size: 20px; float: right" />
          </a-tooltip>
          <a-button v-if="btnEnableList.indexOf(3) > -1" :loading="downLoading" style="margin-left: 8px" @click="exportExcel" icon="download">{{$t('reportQuery.export')}}</a-button>
          <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" v-print="'#reportPrint'" icon="printer">{{$t('reportQuery.print')}}</a-button>
          <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="generatePrintData" icon="printer">{{$t('reportQuery.print')}}</a-button>
        </div>
        <!-- table区域-begin -->
        <section ref="print" id="reportPrint">
          <a-table :customRow="rowClick" ref="table" size="middle" bordered rowKey="id" :columns="columns"
            :dataSource="dataSource" :pagination="ipagination" :scroll="scroll" :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
              <!-- <a @click="myHandleDetail(record, $t('setailManagement.retailDelivery'))">{{
                $t('setailManagement.check')
              }}</a> -->
              <a-popconfirm :ok-text="$t('popup.determine')" :cancel-text="$t('inPrint.cancel')" v-if="btnEnableList.indexOf(7)>-1 && record.status === '1'" :title="$t('popup.confirmReverseAudit')" @confirm="() => myHandleReverseAudit(record)">
                <a type="link">
                  {{$t('manuManagement.DeApproval')}}
                </a>
              </a-popconfirm>
              <a v-if="btnEnableList.indexOf(7)>-1 && record.status === '0'" type="link" :disabled="record.status === '0'">{{$t('manuManagement.DeApproval')}}</a>
              
              <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />
              <!-- <a v-if="btnEnableList.indexOf(1) > -1" @click="myHandleEdit(record)">{{
                  $t('setailManagement.edit')
              }}</a>
              <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />
              <a v-if="btnEnableList.indexOf(1) > -1" @click="myHandleCopyAdd(record)">{{
                  $t('setailManagement.copy')
              }}</a>
              <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" /> -->
              <a-popconfirm v-if="btnEnableList.indexOf(1) > -1" :title="$t('setailManagement.areDelete')"
                @confirm="() => myHandleDelete(record)">
                <a>{{ $t('setailManagement.delete') }}</a>
              </a-popconfirm>
            </span>
            <template slot="customRenderStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">{{ $t('setailManagement.notApproved') }}</a-tag>
              <a-tag v-if="status == '1'" color="green">{{ $t('setailManagement.reviewed') }}</a-tag>
            </template>
            <template slot="purchaseStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">{{ $t('setailManagement.Unsettled') }}</a-tag>
              <a-tag v-if="status == '1'" color="green">{{ $t('setailManagement.Settled') }}</a-tag>
            </template>
          </a-table>
        </section>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <retail-out-modal ref="modalForm" @ok="modalFormOk"></retail-out-modal>
        <bill-detail ref="modalDetail"></bill-detail>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- create ji sheng hua-->
<script>
import RetailOutModal from './modules/RetailOutModal'
import BillDetail from './dialog/BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { BillListMixin } from './mixins/BillListMixin'
import JDate from '@/components/jeecg/JDate'
import { getLanCode } from '@/lang'
import Vue from 'vue'
export default {
  name: 'RetailOutList',
  mixins: [JeecgListMixin, BillListMixin],
  components: {
    RetailOutModal,
    BillDetail,
    JDate,
  },
  data() {
    return {
      lanCode: getLanCode(),
      // 查询条件
      queryParam: {
        number: '',
        materialParam: '',
        type: '出库',
        subType: '零售',
        roleType: Vue.ls.get('roleType'),
        organId: '',
        depotId: '',
        creator: '',
        accountId: '',
        status: '',
        remark: '', 
        status:'1'
      },
      labelCol: {
        span: 5,
      },
      wrapperCol: {
        span: 18,
        offset: 1,
      },
      // 表头
      columns: [
        {title: this.$t('defaultTranslate.lineNumber'), dataIndex: 'rowIndex', width:60, align:"center", customRender: (t,r,index) => t || (parseInt(index) + 1)},
        // { title: this.$t('setailManagement.member'), dataIndex: 'organName', width: 120, ellipsis: true },
        {
          title: this.$t('setailManagement.documentNo'),
          dataIndex: 'number',
          width: 160,
          customRender: (text, record, index)=> {
            if (record.linkNumber) {
              return text + `[${this.$t('otherJS.returnStr')}]`
            } else {
              return text
            }
          },
          sorter: true
        },
        // {
        //   title: this.$t('setailManagement.productInformation'),
        //   dataIndex: 'materialsList',
        //   width: 220,
        //   ellipsis: true,
        //   customRender: function (text, record, index) {
        //     if (text) {
        //       return text.replace(',', '，')
        //     }
        //   },
        // },
        { title: this.$t('setailManagement.documentDate'), dataIndex: 'oper_time', width: 145,
          customRender: function (text, record, index) {
            return record.operTimeStr
          },
          sorter:true},
        { title: this.$t('setailManagement.operator'), dataIndex: 'loginName', width: 80, ellipsis: true },
        { title: this.$t('setailManagement.totalAmount'), dataIndex: 'totalPrice', width: 80 },
        {
          title: this.$t('setailManagement.amountCollected'),
          dataIndex: 'getAmount',
          width: 80,
          customRender: function (text, record, index) {
            if (record.backAmount) {
              return record.changeAmount
            } else {
              return record.changeAmount
            }
          },
        },
        { title: this.$t('setailManagement.giveChange'), dataIndex: 'backAmount', width: 50 },
        {
          title: this.$t('setailManagement.state'),
          dataIndex: 'status',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'customRenderStatus' },
        },
        {
          title: this.$t('setailManagement.settlementStatus'),
          dataIndex: 'purchaseStatus',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'purchaseStatus' },
        },
        {
          title: this.$t('setailManagement.operation'),
          dataIndex: 'action',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/depotHead/list',
        delete: '/depotHead/delete',
        deleteBatch: '/depotHead/deleteBatch',
        deApprovalUrl:'/depotHead/batchCounterAuditStatus',
        batchSetStatusUrl: '/depotHead/batchSetStatus',
      },
    }
  },
  computed: {},
  created() {
    this.initRetail()
    this.getDepotData()
    this.initUser()
    this.initAccount()
    console.log('this.$route :>> ', this.$route);
  },
  methods: {
    lanCodeChange(lanCode) {
      this.$i18n.locale = lanCode
      this.$store.dispatch('setLanCode', lanCode)
      // this.$message({
      //   message: 'Switch Language Success',
      //   type: 'success'
      // })
      /* this.$nextTick(() => {
          this.show = false
        }) */
    },
    rowClick(record, index) {
      return {
        on: {
          click: () => {
          },
          dblclick: () => {
            console.log('双击了我')
            this.myHandleDetail(record, '零售出库')
          },
        }
      }
    },
    
    handleTableChange (pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
        this.queryParam.order = this.isorter.order
        this.queryParam.column = this.isorter.column
      }
      if (pagination && pagination.current) {
        this.ipagination = pagination
      }
      this.loadData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>